package com.jams.goodox.utils;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jams.goodox.R;

/**
 * Created by jams on 2016/7/21.
 * ***
 * Tel: ***
 */

public class TitleSetting {
    private Activity activity;
    private View view;

    public TitleSetting(Activity activity, View view) {
        this.activity = activity;
        this.view = view;
    }

    /**
     * 只有左边返回键
     *
     * @param activity
     * @param title    标题
     */
    public static void titleBackKey(final Activity activity, String title) {
        ((TextView) activity.findViewById(R.id.tv_title_bar_left)).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_right)).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_title)).setText(title);
        ImageView back = (ImageView) activity.findViewById(R.id.iv_title_back);
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
    }

    /**
     * 左右皆是文字
     *
     * @param activity
     * @param title           标题
     * @param leftTv          左边文字
     * @param rightTv         右边文字
     * @param onClickListener 监听
     */
    public static void titleWithBothText(final Activity activity, String title, String leftTv, String rightTv, View.OnClickListener onClickListener) {
        TextView tvLeft = (TextView) activity.findViewById(R.id.tv_title_bar_left);
        TextView tvRight = (TextView) activity.findViewById(R.id.tv_title_bar_right);
        tvLeft.setText(leftTv);
        tvRight.setText(rightTv);
        ((TextView) activity.findViewById(R.id.tv_title_bar_title)).setText(title);
        tvLeft.setOnClickListener(onClickListener);
        tvRight.setOnClickListener(onClickListener);
    }

    /*
     * 只有title
     */
    public static void titleOnlyTitle(final Activity activity,String title){
        ((TextView) activity.findViewById(R.id.tv_title_bar_left)).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_right)).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_title)).setText(title);
    }

    /*
     * 设置左右都是图片
     */
    public static void titleWithBothImage(final Activity activity,String title){
        ((TextView) activity.findViewById(R.id.tv_title_bar_left)).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_right)).setVisibility(View.GONE);
        ((ImageView) activity.findViewById(R.id.iv_title_back)).setVisibility(View.VISIBLE);
        ((ImageView) activity.findViewById(R.id.iv_title_right)).setVisibility(View.VISIBLE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_title)).setText(title);
    }

    /*
     * 设置左边图片 右边文字
     */
    public static void titleLeftIvRightTv(final Activity activity,String title,String rightTv,View.OnClickListener onClickListener){
        ((TextView) activity.findViewById(R.id.tv_title_bar_left)).setVisibility(View.GONE);
        TextView tvRight = ((TextView) activity.findViewById(R.id.tv_title_bar_right));
        tvRight.setVisibility(View.VISIBLE);
        tvRight.setText(rightTv);
        ImageView ivBack = ((ImageView) activity.findViewById(R.id.iv_title_back));
        ivBack.setVisibility(View.VISIBLE);
        ((ImageView) activity.findViewById(R.id.iv_title_right)).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_title)).setText(title);
        tvRight.setOnClickListener(onClickListener);
        ivBack.setOnClickListener(onClickListener);
    }

    //左边是文字，右边无
    public static void titleLeftTv(final Activity activity,String title,String leftTv,View.OnClickListener onClickListener){
        TextView tvLeft = ((TextView) activity.findViewById(R.id.tv_title_bar_left));
        tvLeft.setVisibility(View.VISIBLE);
        tvLeft.setText(leftTv);
        tvLeft.setOnClickListener(onClickListener);
        activity.findViewById(R.id.tv_title_bar_right).setVisibility(View.GONE);
        activity.findViewById(R.id.iv_title_back).setVisibility(View.GONE);
        activity.findViewById(R.id.iv_title_right).setVisibility(View.GONE);
        ((TextView) activity.findViewById(R.id.tv_title_bar_title)).setText(title);
    }
}
